//
//  AppMacro.h
//  FarmTrade
//
//  Created by 翁阿 on 15/9/1.
//  Copyright (c) 2015年 翁阿. All rights reserved.
//

#ifndef FrameDemoNew_AppMacro_h
#define FrameDemoNew_AppMacro_h

#pragma mark - app通用配置

#define WxinMCH_ID  @"1516690451"
/*---------------------------------程序界面配置信息-------------------------------------*/

UIKIT_STATIC_INLINE NSString * mFammaterStringWithObj(NSString *key,id value)
{
    return [NSString stringWithFormat:key,value];
}
//客服部分
#define kScreenWidth [[UIScreen mainScreen] bounds].size.width


#define kMainCellColor [UIColor colorWithRed:248/255.0 green:248/255.0 blue:255/255.0 alpha:1]

#define kInputViewHeight 50

#define QM_IS_IPHONEX (([[UIScreen mainScreen] bounds].size.height-812)?NO:YES)

#define kScreenHeight (QM_IS_IPHONEX ? ([[UIScreen mainScreen] bounds].size.height - 34) : ([[UIScreen mainScreen] bounds].size.height))

//APP导航栏返回按钮图片
#define kDefaultBackImageName @"backImage"
//APP导航栏背景颜色
#define AppNavBarColor  [UIColor colorWithRed:254/255.0 green:85/255.0 blue:1/255.0 alpha:1.0]
//APP导航栏字体颜色
#define AppNavTitleColor  [UIColor whiteColor]

//设置app界面字体及颜色
#define mTitleFont1              [UIFont boldSystemFontOfSize:20]//一级标题字号
#define mTitleFont2              [UIFont boldSystemFontOfSize:17]//二级标题字号
#define mContentFont             [UIFont systemFontOfSize:14.5]  //内容部分字号
#define mTitleFont(font)           [UIFont systemFontOfSize:font]
//自定义字体
#define UIFONT_SC_MEDIUM(fontSize)    [UIFont fontWithName:@"bn_list_card_icon_font" size:fontSize]

//内容部分正常显示颜色和突出显示颜色
#define mContentNormalColor      [UIColor colorWithRed:57/255.0 green:32/255.0 blue:0/255.0 alpha:1]
#define mContentHighlightColor   [UIColor colorWithRed:105/255.0 green:51/255.0 blue:169/255.0 alpha:1.0]
//按钮上字体颜色
#define mBtnTitleNormalColor     [UIColor colorWithRed:57/255.0 green:32/255.0 blue:0/255.0 alpha:1]
#define mBtnTitleHighlightColor  [UIColor colorWithRed:255/255.0 green:96/255.0 blue:0/255.0 alpha:1] //DC6365

//设置应用的页面背景色
#define mAppBgColor  [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1]
#define RGB(a,b,c,p) [UIColor colorWithRed:a/255.0 green:b/255.0 blue:c/255.0 alpha:p]

#define mGetStoryboardViewController(StoryboardName,ClassName) [[UIStoryboard storyboardWithName:StoryboardName bundle:nil]instantiateViewControllerWithIdentifier:ClassName]
#define mGetTableViewCell(CellIdentifier) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]
#define mGetCollectionViewCell(CellIdentifier,IndexPath) [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:IndexPath]

#define mGetStringFromInt(Value)  [NSString stringWithFormat:@"ld",Value]

#pragma mark - 系统

#define mDeviceHeight ([UIScreen mainScreen].bounds.size.height)      //设备高度
#define mSystemVersion   ([[UIDevice currentDevice] systemVersion])   //系统版本
#define mCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0]) //使用语言
#define mAPPVersion      [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] //当前app版本
//判断是否 Retina屏、设备是否%fhone 5、是否是iPad
#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define isPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
//iPhoneX / iPhoneXS
#define  isIphoneX_XS     (kScreenWidth == 375.f && kScreenHeight == 812.f ? YES : NO)
//iPhoneXR / iPhoneXSMax
#define  isIphoneXR_XSMax    (kScreenWidth == 414.f && kScreenHeight == 896.f ? YES : NO)
//加很多分 i 家啊 dfafda

#define mNavBarHeight         44
#define mTabBarHeight         49
#define mScreenWidth          ([UIScreen mainScreen].bounds.size.width)
#define mScreenHeight         ([UIScreen mainScreen].bounds.size.height)
#define getRectNavAndStatusHight  self.navigationController.navigationBar.frame.size.height+[[UIApplication sharedApplication] statusBarFrame].size.height

#define mAppDelegate        (AppDelegate *)[[UIApplication sharedApplication] delegate]
#define mWindow             [[[UIApplication sharedApplication] windows] lastObject]
#define mKeyWindow          [[UIApplication sharedApplication] keyWindow]


#pragma mark - 方法简写 //----------方法简写-------
#define StatusBarStyle_Default [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]
#define StatusBarStyle_Light   [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
#define Navigation_setTitle(navTitle) self.navigationItem.title = navTitle
#define NavigationController_pushVC(viewController) [self.navigationController pushViewController:viewController animated:YES]

#define Color_hexRgb(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define Application_rootViewController  [[[[UIApplication sharedApplication] delegate] window] rootViewController]
#define Application_keyWindow [[UIApplication sharedApplication] keyWindow]
#define Application_openUrl(string) [[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]]
#define WeakSelf(weakSelf) __weak __typeof(self) weakSelf = self
#define Max(x,y)          (((x)>(y)?(x):(y)))
#define kDocuments  [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]
#define mNavitationTitle(Title)  self.navigationItem.title = Title

#define setDickeyobj(dic,obj,key)     [dic setObject:obj forKey:key];
#define dicforkey(dic,key)      [dic objectForKey:key];

#define GLOBAL_QUEUE dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
#define MAIN_QUEUE dispatch_get_main_queue()


#define UserDefaultsSynchronize(uname,key)  \
{ \
[[NSUserDefaults standardUserDefaults] setObject:uname forKey:key]; \
[[NSUserDefaults standardUserDefaults] synchronize];\
}
#define UserDefaultsGetSynchronize(key)  [[NSUserDefaults standardUserDefaults] objectForKey:key]

//简单的以AlertView显示提示信息
#define mAlertView(title, msg) \
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil \
cancelButtonTitle:@"确定" \
otherButtonTitles:nil]; \
[alert show];

#define WS(weakSelf)  __weak __typeof(&*self)weakSelf = self;
//方便使用函数
//加载图片
#define mImageByName(name)        [UIImage imageNamed:name]
#define mImageByPath(name, ext)   [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:name ofType:ext]]
#define mImageByCap(imgname,a,b,c,d)   [[UIImage imageNamed:imgname] resizableImageWithCapInsets:UIEdgeInsetsMake(a, b, c, d)]
//以tag读取View
#define mViewByTag(parentView, tag, Class)  (Class *)[(UIView *)parentView viewWithTag:tag]
//读取Xib文件的类
#define mViewByNib(Class,string, owner) (Class *)[[[NSBundle mainBundle] loadNibNamed:string owner:owner options:nil] lastObject]

//-------------------打印日志-------------------------
#pragma mark - 自定义AxcLog日志打印
#ifdef DEBUG
# define AxcLog(FORMAT, ...) printf("[%s<%p>行号:%d]:%s\n",__FUNCTION__,self,__LINE__,[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String])
#else
# define AxcLog(...);
#endif

//判断是真机还是模拟器
#if TARGET_OS_IPHONE
//iPhone Device
#endif

#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif

//DEBUG  模式下打印日志,当前行
#ifdef DEBUG
#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define DLog(...)
#endif

//重写NSLog,Debug模式下打印日志和当前行数
#if DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil
#endif

//DEBUG  模式下打印日志,当前行 并弹出一个警告
#ifdef DEBUG
#   define ULog(fmt, ...)  { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__]  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
#else
#   define ULog(...)


//-------------------函数-------------------------

//#define getRectNavAndStatusHight \
//({\
//CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];\    CGRect rectNav = self.navigationController.navigationBar.frame;\
//( rectStatus.size.height+ rectNav.size.height);\
//})\



UIKIT_STATIC_INLINE UIColor *toPCcolor(NSString *pcColorstr)
{
    unsigned int c;
    
    if ([pcColorstr characterAtIndex:0] == '#') {
        
        [[NSScanner scannerWithString:[pcColorstr substringFromIndex:1]] scanHexInt:&c];
        
    } else {
        
        [[NSScanner scannerWithString:pcColorstr] scanHexInt:&c];
        
    }
    
    return [UIColor colorWithRed:((c & 0xff0000) >> 16)/255.0 green:((c & 0xff00) >> 8)/255.0 blue:(c & 0xff)/255.0 alpha:1.0];
}

#endif

#endif
